package hhq.demo.ctrl;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import hhq.demo.mapper.BookMarkItemMapper;
import hhq.demo.pojo.ChangeSonFatherObj;
import hhq.demo.pojo.BookMarkItem;
import hhq.demo.utils.ResJson;

@RestController
public class BookMarkItemController {
    @Resource
    BookMarkItemMapper sm;  

    @RequestMapping(value= "/addSon", method=RequestMethod.POST )
    public String addSon(@RequestBody BookMarkItem s){
        try {
            sm.insert(s);
            return ResJson.getString(20, "成功");
        } catch (Exception e) {
            System.err.println(e.toString());
        }
        return ResJson.getString(40, "出错");
    }
    
    @RequestMapping(value= "/updateSon", method=RequestMethod.POST )
    public String updateSon(@RequestBody BookMarkItem s){
        try {
            sm.update(s);
            return ResJson.getString(20, "成功");
        } catch (Exception e) {
            System.err.println(e.toString());
        }
        return ResJson.getString(40, "出错");
    }
    @RequestMapping(value= "/deleteSon/{id}" )
    public String deleteSon(@PathVariable("id") int id){
        try {
            sm.delete(id);
            return ResJson.getString(20, "成功");
        } catch (Exception e) {
            System.err.println(e.toString());
        }
        return ResJson.getString(40, "出错");
    }

    @RequestMapping(value= "/changeSonFather", method = RequestMethod.POST )
    public String changeSonFather(@RequestBody ChangeSonFatherObj csfo){
        try {
            for(int son_id : csfo.getSons_id()){
                sm.changeBookMarkItemFolder(csfo.getFid(), son_id);
            }
            return ResJson.getString(20, "成功");
        } catch (Exception e) {
            System.err.println(e.toString());
        }
        return ResJson.getString(40, "出错");
    }
}